﻿@using Website.Models
@model IEnumerable<Category>

@{
    
    bool gender = bool.Parse(ViewBag.CategoryGender.ToString());
    bool hasCat = Session["catID"] != null;
    if (gender)
    {
        <ul class="category men">
            <li class="title"><a href="#">Thời Trang Nam</a></li>
            @foreach (Category c in Model)
            {
                bool selected = hasCat && int.Parse(Session["catID"].ToString()) == c.CategoryID;
                <li><a href="@Url.Action("Product", "Home", new { catID = c.CategoryID })" @(Html.Raw(selected ? "class=\"selected\"":""))>@c.CategoryName</a>
                @if (c.SubCategories.Count > 0)
                {
                    <ul>
                        @foreach (Category sub in c.SubCategories)
                        {
                            selected = Session["catID"] != null && int.Parse(Session["catID"].ToString()) == sub.CategoryID;
                            <li><a href="@Url.Action("Product", "Home", new { catID = sub.CategoryID })" @(Html.Raw(selected ? "class=\"selected\"":""))>@sub.CategoryName</a></li>
                        }
                    </ul>
                }
                </li>
            }
        </ul>
    }
    else
    {
        <ul class="category women">
            <li class="title"><a href="#">Thời Trang Nữ</a></li>
            @foreach (Category c in Model)
            {
                bool selected = Session["catID"] != null && int.Parse(Session["catID"].ToString()) == c.CategoryID;
                <li><a href="@Url.Action("Product", "Home", new { catID = c.CategoryID })" @(Html.Raw(selected ? "class=\"selected\"":""))>@c.CategoryName</a>
                @if (c.SubCategories.Count > 0)
                {
                    <ul>
                        @foreach (Category sub in c.SubCategories)
                        {
                            selected = Session["catID"] != null && int.Parse(Session["catID"].ToString()) == sub.CategoryID;
                            <li><a href="@Url.Action("Product", "Home", new { catID = sub.CategoryID })" @(Html.Raw(selected ? "class=\"selected\"":""))>@sub.CategoryName</a></li>
                        }
                    </ul>
                }
                </li>
            }
        </ul>
    }
}